package com.myncounters;

import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

import com.google.android.maps.OverlayController;
import com.google.android.maps.Point;


public class myNcounters extends MapActivity {
    /** Called when the activity is first created. */
    
    private LocationManager locationManager;
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
       refresh();
        
       /* List providers = locationManager.getProviders();
        LocationProvider provider = (LocationProvider) providers.get(0);
        Intent intent = new Intent(LOCATION_CHANGED);
        locationManager.requestUpdates(provider, minTime, minDistance, intent);
        */
        
        //Andrej if you want to see the output
        //Uncomment this..
        
        //TextView tv = new TextView(this);
        //tv.setText("lon: "+location.getLongitude()+" lat:"+location.getLatitude());
        //setContentView(tv);
        //setContentView(R.layout.main);
      // R.layout.
    }
    
    public void refresh(){
    	 
        locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
       Location location = locationManager.getCurrentLocation("gps");
       
       MapView mapView = new MapView(this);
       MapController mapController = mapView.getController();
       OverlayController overlayController = mapView.createOverlayController();
       
       locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
       mapController.zoomTo(14);
      
       Double lat = location.getLatitude()*1E6;
       Double lng = location.getLongitude()*1E6;
       Point point = new Point(lat.intValue(), lng.intValue());
       mapController.centerMapTo(point, false);
       myOverlay overlay = new myOverlay(point);
       overlayController.add(overlay, true);
       setContentView(mapView);
    }

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		refresh();
	}
}